package com.lzy.fabric.item.weapon.sword;
import com.lzy.fabric.enchantments.ModEnchantmentInit;
import com.lzy.fabric.events.ModCiteThunder;
import com.lzy.fabric.item.ItemSwordBase;
import com.lzy.fabric.util.CommonFunctions;
import com.lzy.fabric.util.EntityUtil;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.init.MobEffects;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

/**
 * 大保健
 */
public class ItemSwordMassage extends ItemSwordBase {
    public ItemSwordMassage(String name, ToolMaterial material) {
        super(name, material);
        CommonFunctions.addToEventBus(this);
       // MinecraftForge.EVENT_BUS.register(this); -- 原版
    }

    /**
     * 武器事件
     * @param event 事件参数
     */
    @SubscribeEvent
    public void onIncident(LivingHurtEvent event){
        //获取此世界
        World world = event.getEntity().world;
        //判断是否在服务端执行
        if (!world.isRemote){
            //定义受伤者
            EntityLivingBase wounded =  event.getEntityLiving();
            //定义攻击者
            /**
             * getSource() 表示伤害来源
             * getTrueSource() 表示真正的伤害来源
             */
            EntityLivingBase attacker = (EntityLivingBase) event.getSource().getTrueSource();
            //如果攻击者确实存在,攻击者主手里的物品是当前物品
            if (attacker!=null && attacker.getHeldItemMainhand().getItem()==this ){
                // 书写概率事件buff
                if (attacker.getRNG().nextFloat()<0.1f){
                    //原有伤害乘以2 --暴击事件
                    event.setAmount(event.getAmount()*2f);
                }else
                if(attacker.getRNG().nextFloat()<0.3f){
                    //用此物品攻击恢复血量 //攻击者回血buff
                    attacker.heal(2);
                }else
                if(attacker.getRNG().nextFloat()<0.1f){
                    //-- 受伤者中毒buff
                    EntityUtil.ApplyBuff(wounded, MobEffects.POISON,0,10f);
                }else
                if(attacker.getRNG().nextFloat()<0.1f){
                    //攻击者生命恢复buff
                    EntityUtil.ApplyBuff(attacker, MobEffects.REGENERATION,0,10f);
                }

            }


        }
    }




}
